package com.mall.user.utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author ZhaoJiachen on 2021/5/23
 * <p>
 * Description:
 */
public class JwtMsgUtils {
    private static ObjectMapper objectMapper = new ObjectMapper();

    public static String genJwtMsg(Long uid, String username) throws JsonProcessingException {
        Map<String, Object> map = new HashMap<>();
        map.put("uid",uid);
        map.put("username",username);
        String jwtMsg = objectMapper.writeValueAsString(map);
        return jwtMsg;
    }

    public static Map<String,Object> unGenJwgMsg(String jwtMsg) throws IOException {
        Map<String,Object> map = objectMapper.readValue(jwtMsg, Map.class);
        return map;
    }
}
